<template>
  <a-modal
    title="节点管控"
    :width="960"
    :visible="visible"
    :confirmLoading="loading"
    @ok="() => { $emit('ok') }"
    @cancel="() => { $emit('cancel') }"
    footer="">
    <a-spin :spinning="loading">
      <a-form :form="form" v-bind="formLayout">
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="节点类型"
                    :labelCol="{lg: {span: 7}, sm: {span:7}}"
                    :wrapperCol="{lg: {span: 17}, sm: {span: 17} }">
              <BaseInput disabled v-decorator="['controlLevelName',{rules: [{ required: true, message: ' ' }]}]" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="计划开始提示时间(天)"
                    :labelCol="{lg: {span: 7}, sm: {span: 7}}"
                    :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <BaseInputNumber
                      style="width: 100%" disabled
                      v-decorator="['startTipDays',{rules: [{ required: true, message: ' ' }]}]"
                      placeholder=" " />
            </a-form-item>
          </a-col>
        </a-row>

        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="计划结束提示时间(天)"
                    :labelCol="{lg: {span: 7}, sm: {span: 7}}"
                    :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <BaseInputNumber
                      style="width: 100%" disabled
                      v-decorator="['endTipDays',{rules: [{ required: true, message: ' ' }]}]"
                      placeholder=" " />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="红灯亮灯时间(天)"
                    :labelCol="{lg: {span: 7}, sm: {span: 7}}"
                    :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <BaseInputNumber
                      style="width: 100%" disabled
                      v-decorator="['redTipDays',{rules: [{ required: true, message: ' ' }]}]"
                      placeholder=" " />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="黄灯亮灯时间(天)"
                    :labelCol="{lg: {span: 7}, sm: {span: 7}}"
                    :wrapperCol="{lg: {span:17}, sm: {span: 17} }">
              <BaseInputNumber
                      style="width: 100%" disabled
                      v-decorator="['yellowTipDays',{rules: [{ required: true, message: ' ' }]}]"
                      placeholder="" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'

// 表单字段
const fields = ['controlLevelName', 'startTipDays','endTipDays','redTipDays','yellowTipDays',]

export default {
  name:'a'+Date.now(),
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    loading: {
      type: Boolean,
      default: () => false
    },
    model: {
      type: Object,
      default: () => null
    }
  },
  data () {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 }
      }
    }
    return {
      nodeTypes:[{code:1,name:'一级节点'},{code:2,name:'二级节点'},{code:3,name:'三级节点'}],
      form: this.$form.createForm(this)
    }
  },
  created () {

    // 防止表单未注册
    fields.forEach(v => this.form.getFieldDecorator(v))

    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields))
      console.log("hkjfahfjdsfas:",this.model)
    })
  }
}
</script>
